package com.bangmai.api;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bangmai.constant.Header;


import com.bangmai.exception.ServiceException;
import com.bangmai.model.Demo;
import com.bangmai.service.DemoService;
import com.bangmai.view.MessageBean;
@RequestMapping("/demo")
@Controller
public class DemoController {
	Logger logger = LoggerFactory.getLogger(getClass());
	@Resource
	private DemoService demoService;
	
    @RequestMapping(value="save",method = RequestMethod.GET)
    @ResponseBody
    public MessageBean save(Demo demo)
    {	
		MessageBean msg = new MessageBean();
    	try {
			demoService.save(demo);
			msg.setCode(Header.STATUS_SUCESS);
			msg.setMsg("成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			msg.setCode(Header.STATUS_FATAL_ERROR);
			msg.setMsg(e.getMessage());
		}
    	return msg;
    }
    @RequestMapping(value="update",method = RequestMethod.GET)
    @ResponseBody
    public MessageBean update(Demo demo)
    {	
		MessageBean msg = new MessageBean();
    	try {
			demoService.update(demo);
			msg.setCode(Header.STATUS_SUCESS);
			msg.setMsg("成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			msg.setCode(Header.STATUS_FATAL_ERROR);
			msg.setMsg(e.getMessage());
		}
    	return msg;
    }
    
}
